<template>
    <div class="app-container">
        <template v-for="(item,index) in reportMenuList">
            <el-divider content-position="left"><span style="color: #0d30e8">{{ item.menuName }}</span></el-divider>
            <div style="margin-left: 40px;margin-top: 60px;margin-bottom: 60px;">
                <template v-for="(childrenItem,index) in item.children">
                    <el-link :href="url + reportUrlInfo.suffix +'/' + childrenItem.queryParam + '?orgId=' + userInfo.orgId + '&userId=' + userInfo.userId + '&deptId=' + currentSelectDept" class="mr20 link-width" target="_blank"
                             type="primary">
                        {{ childrenItem.menuName }}
                    </el-link>
                </template>
            </div>

        </template>
    </div>
</template>

<script lang="ts" setup>
import {useUserStoreHook} from "@/store/modules/user.ts";
import {getUserReportMenuList} from "@/api/system/menu.ts"

import {useRouter} from 'vue-router'

const router = useRouter()

const {proxy} = getCurrentInstance() as any
const currentSelectDept = proxy.$currentSelectDept

const reportUrlInfo = ref({
    ip: "",
    port: "",
    suffix: ""
})
const reportMenuList = ref<any>([])

const url = ref("http://")

const useUserStore = useUserStoreHook();
// 登录用户信息
const userInfo = <UserInfoBusi>useUserStore.user.userInfo;

function getUserReportMenuListFun() {
    const menuId = router.currentRoute.value.meta.menuId

    getUserReportMenuList({'orgId': userInfo.orgId, 'menuId': menuId}).then((res: any) => {
        let reportMenuListThis: any = [{
            value: 0,
            label: "顶级菜单",
            children: proxy.$handleTree(res.data, "menuId", "menuName")
        }];
        proxy.$getConfigKey("report.url.info").then((response) => {

            if (response.msg) {
                reportUrlInfo.value = JSON.parse(response.msg)
                url.value += reportUrlInfo.value.ip + ':' + reportUrlInfo.value.port
            }
        });
        reportMenuList.value = reportMenuListThis[0].children
    })
}
proxy.$getConfigKey("report.url.info").then((response) => {
    reportUrlInfo.value = response.msg;
});
getUserReportMenuListFun()

</script>

<style scoped>
.link-width {
    width: 180px;
    margin-bottom: 20px;
    font-weight: bold;
}
</style>
